//
//  ReportViewController.m
//  SelfDriving
//
//  Created by apple on 16/4/11.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "ReportViewController.h"
#import "BusinessService+WD.h"
@interface ReportViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *table;
@property (weak, nonatomic) IBOutlet UISwitch *swtIsGetMessage;

@end

@implementation ReportViewController{
    NSMutableArray *data;
    LoginResponseModel *model;
}
-(void)viewWillAppear:(BOOL)animated{
    _swtIsGetMessage.hidden = YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [[BusinessService shareInstance]jubao_list:[[NSMutableDictionary alloc]init] success:^(id result) {
        data = result;
        [_table reloadData];
    } failure:^(id result) {
        [SVProgressHUD showErrorWithStatus:result];
    }];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    if ([_type isEqualToString:@"1"]) {
        return 2;
    }
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return  data.count;
    }
    return 1;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return @"请告诉我们你想举报该用户的理由";
    }
    return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 30;
    }
    return 8;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    if (indexPath.section == 0) {
        LoginResponseModel *models = [data objectAtIndex:indexPath.row];
        cell.textLabel.text = models.name;
    }else{
        if ([_type isEqualToString:@"1"]) {
            cell.textLabel.text = @"同时拉黑";
            cell.accessoryView = _swtIsGetMessage;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            _swtIsGetMessage.hidden = NO;
        }
    }
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    model = [data objectAtIndex:indexPath.row];
}
- (IBAction)switchValueChanged:(id)sender {
    
    
}
#pragma  mark  举报
- (IBAction)submitAction:(UIButton *)sender {
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    if ([_type isEqualToString:@"1"]) {
        [dic setObject:_uid==nil?@"":_uid forKey:@"fid"];
    }
    
    if ([_type isEqualToString:@"5"]) {
        [dic setObject: _content forKey:@"fid"];
    }
    if ([_type isEqualToString:@"6"]) {
        [dic setObject: _content forKey:@"fid"];
    }
    
    if ([_type isEqualToString:@"4"]) {
        [dic setObject: _content forKey:@"fid"];
    }
    

//    [dic setObject:_uid==nil?@"":_uid forKey:@"fid"];
    //xhw2018-1-18改
//    [dic setObject:_type forKey:@"type"];
    if (model) {
        [dic setObject:model.id forKey:@"type"];
    }
    else {
        [SVProgressHUD showErrorWithStatus:@"请选择举报理由"];
        return;
    }
    
    [dic setObject:_type forKey:@"btype"];
    if ([_type isEqualToString:@"3"]) {
        [dic setObject:_content forKey:@"content"];
    }
    if ([_type isEqualToString:@"2"]) {
        [dic setObject:_content forKey:@"content"];
    }

    [[BusinessService shareInstance]jubao:dic
                                  success:^(id result) {
                                      [SVProgressHUD showSuccessWithStatus:@"举报成功"];
                                      [self.navigationController popViewControllerAnimated:YES];
                                      
                                  } failure:^(id result) {
                                      [SVProgressHUD showErrorWithStatus:result];
                                  }];
    
    if ([_type isEqualToString:@"1"]) {  //xhw2018-1-18加这个判断，只有举报的是用户的时候才调用拉黑的接口
        if (_swtIsGetMessage.on) {
            [[BusinessService shareInstance]black:[@{@"fid":_uid,@"type":@"0"} mutableCopy] success:^(id result) {
                [SVProgressHUD showSuccessWithStatus:@"拉黑成功"];
                [self.navigationController popViewControllerAnimated:YES];
                
            } failure:^(id result) {
                [SVProgressHUD showErrorWithStatus:result];
            }];
        }
    }
   
    
}


- (IBAction)backAction:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}



@end
